package com.airticketbooking.service.serviceImpl;

import com.airticketbooking.common.domain.PageQuery;
import com.airticketbooking.common.utils.UserContext;
import com.airticketbooking.po.Employee;
import com.airticketbooking.mapper.EmployeeMapper;
import com.airticketbooking.service.EmployeeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;



@Service
@RequiredArgsConstructor
public class EmployeeServiceImpl implements EmployeeService {

	private final EmployeeMapper employeeMapper;

	@Override
	public Employee getByEmployeeName(String employeeName) {

		Employee employee = employeeMapper.getByEmployeeName(employeeName);

		return employee;
	}

	@Override
	public void add(Employee employee) {
		employee.setStatus(1);
		employee.setHireDate(LocalDate.now());
		employeeMapper.add(employee);

	}

	@Override
	public void modify(Employee employee) {

		employeeMapper.modify(employee);


	}

	@Override
	public Employee getById(Integer employeeId) {

		return employeeMapper.getById(employeeId);
	}

	@Override
	public Page<Employee> getempPage(PageQuery pageQuery) {
		PageHelper.startPage(pageQuery.getPageNo(), pageQuery.getPageSize());

		return employeeMapper.getempPage(pageQuery);
	}

	@Override
	public Employee getEmployeeInfo() {

		Long empId = UserContext.getUser();

		if (empId == null) {
			throw new RuntimeException("未登录");
		}

		return employeeMapper.getById(empId.intValue());

	}
}
